﻿<UserControl x:Class="ReporterControlLibrary.InstanceTree"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:Model="clr-namespace:ReporterEngine.Model;assembly=ReporterEngine"
             xmlns:converters="clr-namespace:ReporterControlLibrary.Converters"
             xmlns:cls="clr-namespace:ReporterControlLibrary"
             mc:Ignorable="d" 
             d:DesignHeight="300" 
             d:DesignWidth="300"
             x:Name="thisUC">  
    <Grid>
        <TreeView x:Name="InstancesTree" Background="{Binding ElementName=thisUC, Path=TreeBackground}" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" ItemsSource="{Binding Mode=OneWay}" Style="{DynamicResource InstancesTreeViewStyle}" ItemContainerStyle="{DynamicResource InstanceTreeViewItemContainerStyle}" >
            <TreeView.Resources>

    			<HierarchicalDataTemplate 
    				DataType="{x:Type Model:InstanceNode}" 
    				ItemsSource="{Binding Categories}">
    				<StackPanel Orientation="Horizontal">
    					<TextBlock Text="{Binding InstanceName}" Style="{DynamicResource FormLabelStyle}" Foreground="{DynamicResource InstanceNodeForeColor}" />
    					<TextBlock Text=" (" Style="{DynamicResource FormLabelStyle}" Foreground="{DynamicResource InstanceNodeForeColor}" />
    					<TextBlock Text="{Binding TypeName}" Style="{DynamicResource FormLabelStyle}" Foreground="{DynamicResource InstanceNodeForeColor}" />
    					<TextBlock Text=")" Style="{DynamicResource FormLabelStyle}" Foreground="{DynamicResource InstanceNodeForeColor}" />
    				</StackPanel>
    			</HierarchicalDataTemplate>

    			<HierarchicalDataTemplate 
    				DataType="{x:Type Model:InstanceReference}" 
    				ItemsSource="{Binding ReferenceNode.Categories}">    				
    				<StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding PropertyName}" Foreground="{DynamicResource InstanceReferenceNodeForeColor}" Style="{DynamicResource FormLabelStyle}"/>
                        <TextBlock Text=" : " Foreground="{DynamicResource InstanceReferenceNodeForeColor}" Style="{DynamicResource FormLabelStyle}" />
                        <TextBlock Text="{Binding ReferenceNode.InstanceName}" Foreground="{DynamicResource InstanceReferenceNodeForeColor}" Style="{DynamicResource FormLabelStyle}" />
                        <TextBlock Text=" (" Foreground="{DynamicResource InstanceReferenceNodeForeColor}" Style="{DynamicResource FormLabelStyle}" />
                        <TextBlock Text="{Binding ReferenceNode.TypeName}" Foreground="{DynamicResource InstanceReferenceNodeForeColor}" Style="{DynamicResource FormLabelStyle}" />
                        <TextBlock Text=")" Foreground="{DynamicResource InstanceReferenceNodeForeColor}" Style="{DynamicResource FormLabelStyle}" />
    				</StackPanel>
    			</HierarchicalDataTemplate>

    			<HierarchicalDataTemplate 
    				DataType="{x:Type Model:InstanceUsedBy}" 
    				ItemsSource="{Binding UsedByNode.Categories}">
    				<StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding PropertyName}" Foreground="{DynamicResource InstanceUsedByNodeForeColor}" Style="{DynamicResource FormLabelStyle}" />
                        <TextBlock Text=" : " Foreground="{DynamicResource InstanceUsedByNodeForeColor}" Style="{DynamicResource FormLabelStyle}" />
                        <TextBlock Text="{Binding UsedByNode.InstanceName}" Foreground="{DynamicResource InstanceUsedByNodeForeColor}" Style="{DynamicResource FormLabelStyle}" />
                        <TextBlock Text=" (" Foreground="{DynamicResource InstanceUsedByNodeForeColor}" Style="{DynamicResource FormLabelStyle}" />
                        <TextBlock Text="{Binding UsedByNode.TypeName}" Foreground="{DynamicResource InstanceUsedByNodeForeColor}" Style="{DynamicResource FormLabelStyle}" />
                        <TextBlock Text=")" Foreground="{DynamicResource InstanceUsedByNodeForeColor}" Style="{DynamicResource FormLabelStyle}" />
    				</StackPanel>
    			</HierarchicalDataTemplate>

    			<HierarchicalDataTemplate 
    				DataType="{x:Type Model:InstanceCategory}" 
    				ItemsSource="{Binding Childs}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding CategoryName}" Style="{DynamicResource FormLabelStyle}" Foreground="{Binding Converter={StaticResource InstanceTreeItemForeColorConverter}}" />
                        <TextBlock Text=" (" Style="{DynamicResource FormLabelStyle}" Foreground="{Binding Converter={StaticResource InstanceTreeItemForeColorConverter}}" />
                        <TextBlock Text="{Binding Childs.Count}" Style="{DynamicResource FormLabelStyle}" Foreground="{Binding Converter={StaticResource InstanceTreeItemForeColorConverter}}" />
                        <TextBlock Text=")" Style="{DynamicResource FormLabelStyle}" Foreground="{Binding Converter={StaticResource InstanceTreeItemForeColorConverter}}" />
    				</StackPanel>
    			</HierarchicalDataTemplate>

    			<DataTemplate DataType="{x:Type Model:InstanceProperty}">
    				<StackPanel Orientation="Horizontal" Background="{x:Null}">
                        <TextBlock Text="{Binding PropertyName}" TextDecorations="{Binding PropertyValue, Converter={StaticResource InstanceTreeBlankValueConverter}}" Foreground="{DynamicResource InstancePropertyNodeForeColor}" Style="{DynamicResource FormLabelStyle}" />
                        <TextBlock Text=" : " TextDecorations="{Binding PropertyValue, Converter={StaticResource InstanceTreeBlankValueConverter}}" Foreground="{DynamicResource InstancePropertyNodeForeColor}" Style="{DynamicResource FormLabelStyle}" />
                        <TextBlock Text="{Binding PropertyValue, Converter={StaticResource MaxInstanceTreeLengthConverter}}" ToolTip="{Binding PropertyValue}" Foreground="{DynamicResource InstancePropertyNodeForeColor}" Style="{DynamicResource FormLabelValueStyle}" />
    				</StackPanel>
    			</DataTemplate>

                <DataTemplate DataType="{x:Type Model:InstanceValue}">
                    <StackPanel Orientation="Horizontal" Background="{x:Null}">
                        <TextBlock Text="{Binding Value, Converter={StaticResource MaxInstanceTreeLengthConverter}}" ToolTip="{Binding Value}" Foreground="{DynamicResource InstanceValueNodeForeColor}" Style="{DynamicResource FormLabelValueStyle}" />
                    </StackPanel>
                </DataTemplate>

            </TreeView.Resources>
        </TreeView>
    </Grid>
</UserControl>
